import { createRouter, createWebHashHistory } from 'vue-router'
/**
 * 1.导入组件
 * 2.在routes数组中配置
 */
// 公共布局=>多有页面的骨架
// 路由按需加载原理=>默认加载的是一个函数=>什么时候执行=>访问某个路由,执行某个页面component配置的函数
// import Layout from '@/views/Layout'
const Layout = () => import('@/views/Layout')
// 首页
// import Home from '@/views/Home/index.vue'
const Home = () => import('@/views/Home/index.vue')

const Category = () => import('@/views/Category/index.vue')
const CategorySub = () => import('@/views/Category/sub.vue')
const Goods = () => import('@/views/Goods/index.vue')
const Login = () => import('@/views/Login/index.vue')
const LoginCallBack = () => import('@/views/Login/callback')
const Cart = () => import('@/views/Cart')
const Pay = () => import('@/views/Member/pay/index.vue')
const PayResult = () => import('@/views/Member/pay/result.vue')
const PayOrder = () => import('@/views/Member/order/index.vue')

// 下单组件
const Settlement = () => import('@/views/Member/settlement')

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      // 首页
      {
        path: '',
        component: Home
        // 一级分类页面
      },
      {
        path: '/category/:id',
        component: Category
      },

      {
        path: '/category/sub/:id',
        component: CategorySub
      },
      // 商品详情
      {
        path: '/goods/:id',
        component: Goods
      },
      {
        path: '/cart',
        component: Cart
      }, {
        path: '/settlement',
        component: Settlement
      }, {
        path: '/pay',
        component: Pay
      }, {
        path: '/pay/callback',
        component: PayResult
      }, {
        path: '/order',
        component: PayOrder
      }
    ]
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/login/callback',
    component: LoginCallBack
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

export default router
